package utils;



import java.sql.*;

public class JDBCUtils {
    public static Connection getConnection() throws SQLException,ClassNotFoundException {//获取连接对象的静态方法
        Class.forName("com.mysql.jdbc.Driver");
        return DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","123456");
    }

    public static void release(Statement statement,Connection connection){
        if(statement!=null){
            try{
                statement.close();
            }catch (SQLException e){
                e.printStackTrace();
            }
            statement=null;
        }
        if(connection!=null){
            try{
                statement.close();
            }catch (SQLException e){
                e.printStackTrace();
            }
            connection=null;
        }
    }

    public static void release(ResultSet resultSet,Statement statement, Connection connection){
        if(statement!=null){
            try{
                statement.close();
            }catch (SQLException e){
                e.printStackTrace();
            }
            statement=null;
        }
        if(connection!=null){
            try{
                connection.close();
            }catch (SQLException e){
                e.printStackTrace();
            }
            connection=null;
        }
        if(resultSet!=null){
            try{
                resultSet.close();
            }catch (SQLException e){
                e.printStackTrace();
            }
            resultSet=null;
        }
    }
}
